package com.lzy.cloud.order.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.lzy.cloud.order.dtos.OrderRefundDto;
import com.lzy.cloud.order.entity.OrderRefund;
import com.lzy.cloud.order.mapper.OrderRefundMapperExt;
import com.lzy.cloud.order.service.OrderRefundService;
import com.lzy.framework.core.orm.db.Pager;
import com.lzy.framework.core.utils.DozerUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Description: 订单退换货金额明细
 * @Author:   gyl
 * @Date:     2018/7/10 20:23
 */
@Service
public class OrderRefundServiceImpl implements OrderRefundService {

    @Autowired
    private OrderRefundMapperExt orderRefundMapperExt;

    @Override
    public PageInfo<OrderRefundDto> queryList(Pager pager, OrderRefundDto orderRefundDto) {
        if (pager != null)
            PageHelper.startPage(pager.getPageNum(), pager.getPageSize());
        return new PageInfo<>(orderRefundMapperExt.queryList(orderRefundDto));
    }

    @Override
    public OrderRefundDto queryListByOrderId(String orderId) {
        return orderRefundMapperExt.queryListByOrderId(orderId);
    }

    @Override
    public Long create(OrderRefundDto orderRefundDto) {
        OrderRefund orderRefund = DozerUtils.map(orderRefundDto, OrderRefund.class);
        return orderRefundMapperExt.insertSelective(orderRefund)>0 ? orderRefund.getId() : 0;
    }

    @Override
    public Boolean update(OrderRefundDto orderRefundDto) {
        return orderRefundMapperExt.updateByPrimaryKeySelective(DozerUtils.map(orderRefundDto, OrderRefund.class)) > 0;
    }
}
